package com.edgclub.edg.uc;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.edgclub.edg.R;

/**
 * 确定取消的对话框
 * 
 * @author 陈坤彬
 *
 */
public class UpdateDialog extends Dialog {

	private TextView title;
	private TextView content;
	private TextView tvOk, tvCancle;

	private Context context;

	private Dialog dialog;

	private SubmitClickListener onSubmitClickListener;

	private UpdateDialog instance;

	private ImageView line;

	// public static DeleteDialog create(Context context) {
	// DeleteDialog instance = new DeleteDialog(context);
	//
	// return instance;
	//
	// }

	public static UpdateDialog create(Context context, boolean hasCancle) {
		UpdateDialog instance = new UpdateDialog(context, hasCancle);
		return instance;

	}

	private UpdateDialog(Context context, boolean hasCancle) {
		super(context, R.style.MyAlertDialog);
		init(context, hasCancle);
	}

	private void init(Context context, boolean hasCancle) {
		this.context = context;
		WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
		lp.width = context.getResources().getDisplayMetrics().widthPixels;
		View contentView = LayoutInflater.from(context).inflate(
				R.layout.layout_update_dialog, null);

		setContentView(contentView, lp);
		line = (ImageView) contentView.findViewById(R.id.line);
		tvOk = (TextView) contentView.findViewById(R.id.tv_ok);
		tvCancle = (TextView) contentView.findViewById(R.id.tv_cancel);
		title = (TextView) contentView.findViewById(R.id.tv_title);
		content = (TextView) contentView.findViewById(R.id.tv_content);
		if (hasCancle) {
			tvCancle.setVisibility(View.VISIBLE);
			line.setVisibility(View.VISIBLE);
		} else {
			tvCancle.setVisibility(View.GONE);
			line.setVisibility(View.GONE);
		}
	}
	/**
	 * 设置确认的监听
	 */
	public void setSubmitListener(
			final SubmitClickListener onSubmitClickListener) {
		tvOk.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				if (null != onSubmitClickListener) {
					onSubmitClickListener.submitClick();
				}
			}
		});
	}

	/**
	 * 设置取消的监听
	 */
	public void setCancelListener(
			final CancelClickListener onCancelClickListener) {
		tvCancle.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				if (null != onCancelClickListener) {
					onCancelClickListener.cancelClick();
				}
			}
		});
	}

	public void setTitle(int res) {
		setTitle(context.getResources().getString(res));
	}

	public void setTitle(String title) {
		this.title.setText(title);
	}

	public void setContent(int res) {
		setContent(context.getResources().getString(res));
	}

	public void setContent(String content) {
		this.content.setText(content);
	}

	public interface SubmitClickListener {
		public void submitClick();

	}

	public interface CancelClickListener {
		public void cancelClick();
	}

	public void setSubmittext(String content) {
		this.tvOk.setText(content);
	}
	public void setCancle(String content) {
		this.tvCancle.setText(content);
	}
	
	public void setTvOkColor(int color){
		this.tvOk.setTextColor(color);
	}
	
	public void setTvTitleColor(int color){
		this.title.setTextColor(color);
	}
	
	public TextView getTvOk() {
		return tvOk;
	}

	

}
